﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Project01
{
    class Boss02 : Monster
    {
        private float Angle;
        private TimeSpan TimeShoot;
        private bool CreateBullets;

        private MonsterMove M = MonsterMove.Left;
        public Boss02(Game game)
            : base(game)
        {
            this.ObjectTexture = game.Content.Load<Texture2D>("Images/Boss/Boss1");
            this.Sprite = new AnimationSprite(ObjectTexture, 1, 1);
            this.Speed = 3;
            this.Health = 50;
            this.game = game;
            Type = 248;
        }

        private void LoadBullets(int Couter)
        {
            Console.WriteLine(Couter);
            if (Couter <= 75)
            {
                CreateBulletsconsecutive(new Vector2(Sprite.Position.X + 10, Sprite.Position.Y + 10), Angle);
            }
            else if (Couter > 75 && Couter <= 90)
            {
                CreateBulletsCirCle(13, .5f, new Vector2(Sprite.Position.X + 10, Sprite.Position.Y + 10));
            }
            else
            {
                CreateBulletsCirCle(10, 0.3f, new Vector2(Sprite.Position.X + 10, Sprite.Position.Y + 10));
            }

        }
        public override void Update(GameTime gameTime)
        {
            Angle += (float)gameTime.ElapsedGameTime.TotalSeconds;

            Exp.Sprite.Position = SetPositionExplosion(Sprite.Position, -5, 0);

            if (Sprite.Position.Y <= 0 + Sprite.RecHeight)
            {
                Sprite.Position = Move.MoveVertical(Sprite.Position, -Speed);
                Sprite.Position = Move.MoveHorizontal(Sprite.Position, -Speed);

            }
            else
            {
                ////Sprite.Position = Sprite.Position = Move.MoveHorizontal(Sprite.Position, -Speed);
                //if (Sprite.Position.X <= game.Window.ClientBounds.Width - Sprite.RecWidth)
                //{
                //    Sprite.Position = Sprite.Position = Move.MoveHorizontal(Sprite.Position, -Speed);
                //}
                //else if (Sprite.Position.X >= 0 + Sprite.RecWidth)
                //{
                //    Sprite.Position = Sprite.Position = Move.MoveHorizontal(Sprite.Position, Speed);
                //}
                CreateBullets = true;
                TimeShoot += gameTime.ElapsedGameTime;
            }
            if (CreateBullets)
            {
                if (TimeShoot >= TimeSpan.FromSeconds(0.3f))
                {
                    LoadBullets(Ran.ran.Next(1, 101));

                    TimeShoot = TimeSpan.Zero;
                }
            }
            UpdateBullets(Speed);
            Active = CheckPosition(Sprite.Position);
            base.Update(gameTime);
        }
        public override void Draw(SpriteBatch SpriteBatch)
        {
            for (int i = 0; i < Mbullets.Count; i++)
                Mbullets[i].Draw(SpriteBatch);
            base.Draw(SpriteBatch);
        }
        private void CreateBulletsconsecutive(Vector2 Position, float angle)
        {
            for (int i = 1; i <= 2; i++)
            {
                Bullets B = new Bullets(game, "Images/Bullets/Monster/B_M_Type03", 1, 1);
                B.Sprite.Position = new Vector2(Position.X + (50 * i), Position.Y);
                angle = (float)Math.PI / Ran.NextFloat(Ran.ran, 1.2f, 2.5f);
                B.Sprite.Rotation = angle;
                Mbullets.Add(B);
            }
        }
        private void CreateBulletsCirCle(int number, float angle, Vector2 Position)
        {
            for (int i = 1; i <= number; i++)
            {
                Bullets B = new Bullets(game, "Images/Bullets/Monster/B_M_Type03", 1, 1);
                B.Sprite.Rotation = angle * i;
                B.Sprite.Position = Position;
                Mbullets.Add(B);
            }
        }

        private void UpdateBullets(float Speed)
        {
            for (int i = 0; i < Mbullets.Count; i++)
            {
                Mbullets[i].Sprite.Update();
                Mbullets[i].Sprite.Position += new Vector2(Move.toAngle(Mbullets[i].Sprite.Rotation).X * Speed, Move.toAngle(Mbullets[i].Sprite.Rotation).Y * Speed);
                if (Mbullets[i].Sprite.Position.X <= 0 - Mbullets[i].Sprite.RecWidth || Mbullets[i].Sprite.Position.X >= game.Window.ClientBounds.Width + Mbullets[i].Sprite.RecWidth ||
                   Mbullets[i].Sprite.Position.Y <= 0 - Mbullets[i].Sprite.RecHeight || Mbullets[i].Sprite.Position.Y >= game.Window.ClientBounds.Height + Mbullets[i].Sprite.RecHeight)
                {
                    Mbullets[i] = null;
                    Mbullets.RemoveAt(i);
                    i--;
                }
            }
        }
    }
}
